/******************************************************************************
 * Filename : uc_prcom.h
 * Copyright:
 * Created  : 2014-4-11 by franco.yin
 * Description -
 *
 ******************************************************************************/

#ifndef __UCPRCOM_H__
#define __UCPRCOM_H__

#ifdef __cplusplus
	 extern "C" {
#endif

#include <stdint.h>

#define UCPRCOM_FLAG_YUV		0x00000001
#define UCPRCOM_FLAG_PCM		0x00000002
#define UCPRCOM_FLAG_TS		0x00000004
#define UCPRCOM_FLAG_PIC		0x00000008

#define UCPRCOM_SHRM_KEY			0x000f39fb
#define UCPRCOM_SHRM_CACHE		5
#define UCPRCOM_SHRM_CLI_MAX		5
#define UCPRCOM_SHRM_V_MAX		(1024 * 1024 * 5)
#define UCPRCOM_SHRM_A_MAX		(1024 * 1024)
#define UCPRCOM_SHRM_TS_MAX		(1024 * 1024 * 2)
#define UCPRCOM_SHRM_PIC_MAX		(1024 * 1024 * 8)
#define UCPRCOM_SHRM_GPS_MAX		512

#define UCPRCOM_SHRM_PLATE_CNT_MAX	5
#define UCPRCOM_SHRM_PLATE_LEN_MAX	32

typedef enum _ucprcom_data_type{
	UCPRCOM_DATA_TYPE_YUV,
	UCPRCOM_DATA_TYPE_PCM,
	UCPRCOM_DATA_TYPE_TS,
	UCPRCOM_DATA_TYPE_PIC,

	UCPRCOM_DATA_TYPE_MAX
}ucprcom_data_type_e;

#pragma pack(4)

typedef struct _ucprcom_v_fmt {
	uint16_t width;
	uint16_t height;
	uint16_t yuv_fmt;
	uint8_t fps;
	uint8_t interlace;
} ucprcom_v_fmt_s;

typedef struct _ucprcom_a_fmt {
	uint8_t	channel;
	uint8_t fmt;
	uint8_t sample;
	uint8_t endia;
	uint32_t reserve;
} ucprcom_a_fmt_s;

typedef struct _ucprcom_ts_fmt {
	uint32_t pkt_size;
	uint32_t reserve;
} ucprcom_ts_fmt_s;

typedef struct _ucprcom_bmp_fmt {
	uint16_t width;
	uint16_t height;
	uint32_t type;//1-bmp,2-jpg
} ucprcom_bmp_fmt_s;

typedef struct _ucprcom_timestamp {
	uint32_t sec;
	uint32_t usec;
} ucprcom_timestamp_s;

typedef struct _ucprcom_plate {
	char plate_gb2312[UCPRCOM_SHRM_PLATE_LEN_MAX];
	char plate_utf8[UCPRCOM_SHRM_PLATE_LEN_MAX];
	uint32_t reco_level;
	uint32_t plate_color;
	uint32_t x1;
	uint32_t y1;
	uint32_t x2;
	uint32_t y2;
} ucprcom_plate_s;

typedef struct _ucprcom_av_fmt {
	ucprcom_timestamp_s timestamp;
	char gps_info[UCPRCOM_SHRM_GPS_MAX];
	uint32_t index;
	uint32_t plate_cnt;
	ucprcom_plate_s plate[UCPRCOM_SHRM_PLATE_CNT_MAX];
	union {
		ucprcom_v_fmt_s yuv;
		ucprcom_a_fmt_s pcm;
		ucprcom_ts_fmt_s ts;
		ucprcom_bmp_fmt_s pic;
	};
} ucprcom_av_fmt_s;

#pragma pack()

typedef void (*ucprcom_func)(int type, ucprcom_av_fmt_s *pFmt, uint8_t *pData, int len, void *p);


extern void ucprcom_uptime(ucprcom_timestamp_s *pTimestamp, ucprcom_timestamp_s *pLastTimestamp, int fps);

extern void *ucprcom_srv_creat(ucprcom_func pFunc, void *p);
extern int ucprcom_srv_getp(void *pUCPrcom, int type, ucprcom_av_fmt_s **ppFmt, uint8_t **ppData, int *pDataMaxLen);
extern int ucprcom_srv_putp(void *pUCPrcom, int type, int if_ok, int data_len, int if_outpout);
extern void ucprcom_srv_free(void *pUCPrcom);

extern int ucprcom_cli_creat();
extern int ucprcom_cli_start(uint32_t flag, ucprcom_func func, void *p);
extern int ucprcom_cli_stop();
extern void ucprcom_cli_get_input(int *pInpsel, int *pVfmt, int *pWidth, int *pHeight, int *pFps, int *pInterlace);


#ifdef __cplusplus
}
#endif

#endif

